#include <pspiofilemgr.h>
unsigned int *words, *indicies;

int LoadWords(int lang)
{
	int fd;
	
	char fpath[] = sprintf("lang%d.lan",lang);
	fd = sceIoOpen(fpath, PSP_O_RDONLY, 0777);
	if (fd < 0)
		return -1;

	char masterarray[GetFileLen(fd)];
	sceIoRead(fd, *masterarray[], sizeof(masterarray[])); // words

	SplitArrays(&masterarray);

	sceIoClose(fd);
	free(&fd);
	free(&masterarray);
	return 1;
}
int GetFileLen(int fileID)
{
	int ret = sceIoLseek(fileID, 0, PSP_SEEK_END);
	int temp = sceIoLseek(fileID, 0, PSP_SEEK_SET);
	free(&temp);
	return ret;
}
void SplitArrays(unsigned int *aray)
{
	int count, arrayPosition;
	char w[len]; //words
	unsigned long idx[len]; //indicies

	for (int i = 0; i <= sizeof(*aray); i++)
	{
		count = getCount(i)

		unsigned long temp;
		char TemP[count-1];			// array bounds are 0 based, count is 1 based

		temp = *aray;				// start off splitting the array, first # of index
		*aray += count + 1;			// switch to words
		TemP[0] = (char)*aray		// first char of word
		*aray -= count;				// back to index for loop

		for (int j = 0; j < count; j++)
		{
			temp *=	10				// 1:123 > 10:123
			temp += *aray;			// 10:123 > 12:123
			aray += (count + 1);	// switch to word
			TemP[j+1] = (char)*aray;// a--:abc > ab-:abc
			aray -= (count);		// switch back to index for next pass
		}
		arrayPosition ++;
	}
	words = &w[0];
	indicies = &idx[0];
}
int getCount(int start, unsigned int *aray) // 1 based length
{
	*aray += start;
	unsigned short i, flag;
	while (flag != (int)'|')
	{
		flag = (unsigned short)*aray ++;
		i ++;
		if (i == 30)	// no word is more than 30 chars long
			return -1;
	}
	return i;
}
